﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Star : MonoBehaviour {

    public float m_TriggerDistance = 1.5f;
    public float m_ExplosionTime = 5.0f;

    private PlayerMove m_player;
    private bool m_hasArrived = false;

    private void Awake()
    {
        m_player = GameObject.Find("Player").GetComponent<PlayerMove>();
    }

    private void Update()
    {
        if ((transform.position - m_player.transform.position).magnitude <= m_TriggerDistance && !m_hasArrived)
        {
            m_hasArrived = true;

            m_player.transform.position = transform.position - new Vector3(0, m_TriggerDistance, 0);
            m_player.m_StarObj = gameObject;
            m_player.gameObject.GetComponent<Rigidbody2D>().velocity = 
                new Vector3(-m_player.m_LinerSpeed, 0, 0);
            m_player.transform.rotation = Quaternion.identity;
            m_player.SetCircleMode();

            Invoke("Disappear", m_ExplosionTime);
        }
    }

    private void Disappear()
    {
        gameObject.SetActive(false);
    }
}
